﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinCourseControls
{
    public partial class FrmPrintControls : Form
    {
        public FrmPrintControls()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 打印设置对话框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrintSetting_Click(object sender, EventArgs e)
        {
            pageSetupDialog1.ShowDialog();//显示打印设置对话框
        }

        /// <summary>
        /// 打印预览按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPreview_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.ShowDialog(); // 显示打印预览对话框
        }

        /// <summary>
        /// 打印按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if(printDialog1.ShowDialog()==DialogResult.OK) // 打印对话框
            {
                printDocument1.Print();//打印输出  引发PrintDocument的PrintPage事件
            }
        }

        /// <summary>
        /// 打印页内容时发生 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //要打印的信息画出来

            Graphics g = e.Graphics; // 创建绘图对象
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // 设置呈现质量
            Pen pen = new Pen(Color.Black, 1); // 实例化笔对象，用于画线
          

            //画文字 
            int start = 70, top = 40;
            for (int i = 0; i < 5; i++)
            {
                Rectangle rect = new Rectangle(panel1.Left, panel1.Top+i*180, panel1.Width, panel1.Height); // 矩形框对象
                g.DrawRectangle(pen, rect); // 画矩形框框效果
                g.DrawString(label7.Text, label7.Font, new SolidBrush(label7.ForeColor), start, top + i * 180); // 画文本
                g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), start, top + i * 180 + 30);
                g.DrawString(label2.Text, label2.Font, new SolidBrush(label2.ForeColor), start + 50, top + i * 180 + 30);
                g.DrawString(label3.Text, label3.Font, new SolidBrush(label3.ForeColor), start, top + i * 180 + 60);
                g.DrawString(label4.Text, label4.Font, new SolidBrush(label4.ForeColor), start + 50, top + i * 180 + 60);
                g.DrawString(label6.Text, label6.Font, new SolidBrush(label6.ForeColor), start, top + i * 180 + 90);
                g.DrawString(label5.Text, label5.Font, new SolidBrush(label5.ForeColor), start + 50, top + i * 180 + 90);
                //画照片
                g.DrawImage(pictureBox1.Image, new Rectangle(start + 180, top + i * 180, pictureBox1.Width, pictureBox1.Height));
            }
          

            //Rectangle rect1 = new Rectangle(panel1.Left, panel1.Top+180, panel1.Width, panel1.Height);
            //g.DrawRectangle(pen, rect1);
            //g.DrawString(label7.Text, label7.Font, new SolidBrush(label7.ForeColor), start, top+180);
            //g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), start, top + 180 + 30);
            //g.DrawString(label2.Text, label2.Font, new SolidBrush(label2.ForeColor), start + 50, top + 180 + 30);
            //g.DrawString(label3.Text, label3.Font, new SolidBrush(label3.ForeColor), start, top + 180 + 60);
            //g.DrawString(label4.Text, label4.Font, new SolidBrush(label4.ForeColor), start + 50, top + 180 + 60);
            //g.DrawString(label6.Text, label6.Font, new SolidBrush(label6.ForeColor), start, top + 180 + 90);
            //g.DrawString(label5.Text, label5.Font, new SolidBrush(label5.ForeColor), start + 50, top + 180 + 90);
            ////画照片
            //g.DrawImage(pictureBox1.Image, new Rectangle(start + 180, top + 180, pictureBox1.Width, pictureBox1.Height));
        }
    }
}
